#pragma once
#include <grpcpp/grpcpp.h>
#include "const.h"
#include "proto/message.grpc.pb.h"

using grpc::Channel;
using grpc::Status;
using grpc::ClientContext;

class StatusConPool
{
public:
	StatusConPool(size_t poolsize, std::string host, std::string port);
	~StatusConPool();
	std::unique_ptr<message::StatusService::Stub> getStub();
	void returnStub(std::unique_ptr<message::StatusService::Stub>);
	void Close();
private:
	std::atomic<bool> _b_stop;
	size_t _poolsize;
	std::string _host;
	std::string _port;
	std::queue<std::unique_ptr<message::StatusService::Stub>> _stubs;
	std::mutex _mtx;
	std::condition_variable _condvar;

};

class StatusGrpcClient {
public:
	static StatusGrpcClient& GetInst();
	message::GetChatServerRsp GetChatServer(int uid);
	~StatusGrpcClient();
private:
	StatusGrpcClient();
	std::unique_ptr<StatusConPool> _pool;
};